import java.util.*;

public class Work {

    //只出现一次的元素
    public int singleNumber(int[] nums){
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            if(!set.contains(nums[i])){
                set.add(nums[i]);
            }else{
                set.remove(nums[i]);
            }
        }
        for (int i = 0; i < nums.length; i++) {
            if(set.contains(nums[i])){
                return nums[i];
            }
        }
        return -1;
    }

    public class Node{
        public int val;
        public Node random;
        public Node next;

        public Node(int val) {
            this.val = val;
        }
    }

    //随机链表的复制
    public Node copyRandomList(Node head) {
        HashMap<Node,Node> map = new HashMap<>();
        //第一次遍历
        Node cur = head;
        while(cur != null){
            Node node = new Node(cur.val);
            map.put(cur,node);
            cur = cur.next;
        }
        cur = head;

        //第二次遍历
        Node curN = cur;
        while(cur != null){
            map.get(cur).next = map.get(cur.next);
            map.get(cur).random = map.get(cur.random);
            cur = cur.next;
        }
        return map.get(cur);
    }

    //宝石与石头
    public int numJewelsInStones(String jewels, String stones) {
        Set<Character> set = new HashSet<>();
        //第一次遍历，确定宝石类型
        for(int i = 0;i < jewels.length();i++){
            if(!set.contains(jewels.charAt(i))){
                set.add(jewels.charAt(i));
            }
        }

        //第二次遍历，确定石头中的宝石
        int count = 0;
        for(int i = 0; i < stones.length();i++){
            if(set.contains(stones.charAt(i))){
                count++;
            }
        }
        return count;
    }

    //旧键盘
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str1 = in.nextLine();
            String str2 = in.nextLine();
            func(str1, str2);
        }
    }

    public static void func(String s1, String s2) {
        String str1 = s1.toUpperCase();
        String str2 = s2.toUpperCase();
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < str2.length(); i++) {
            if (!set.contains(str2.charAt(i))) {
                set.add(str2.charAt(i));
            }
        }
        Set<Character> setC = new HashSet<>();
        for (int i = 0; i < str1.length(); i++) {
            if (!set.contains(str1.charAt(i)) &&
                    !setC.contains(str1.charAt(i))) {
                setC.add(str1.charAt(i));
                System.out.print(str1.charAt(i));
            }
        }
    }

    //前K个高频单词
    public List<String> topKFrequent(String[] words, int k) {
        List<String> list = new ArrayList();
        int[] count = new int[words.length];
        List<Integer> nums = new ArrayList();
        Map<String, Integer> map = new HashMap<String, Integer>();
        for (int i = 0; i < words.length; i++) {
            if (!map.containsKey(words[i])) {
                count[i]++;
                map.put(words[i], i);
            } else {
                count[map.get(words[i])]++;
            }
        }
        for (int i = 0; i < k; i++) {
            int max = 0;
            for (int j = 1; j < count.length; j++) {
                if (count[j] > count[max]) {
                    max = j;
                } else if (count[j] == count[max]) {
                    max = words[max].compareTo(words[j]) < 0 ? max : j;
                }
            }
            count[max] = 0;
            list.add(words[max]);
        }
        return list;
    }


    public List<String> topKFrequent2(String[] words, int k) {
        Map<String, Integer> cnt = new HashMap<String, Integer>();
        for (String word : words) {
            cnt.put(word, cnt.getOrDefault(word, 0) + 1);
        }
        List<String> rec = new ArrayList<String>();
        for (Map.Entry<String, Integer> entry : cnt.entrySet()) {
            rec.add(entry.getKey());
        }
        Collections.sort(rec, new Comparator<String>() {
            public int compare(String word1, String word2) {
                return cnt.get(word1) == cnt.get(word2)
                        ? word1.compareTo(word2)
                        : cnt.get(word2) - cnt.get(word1);
            }
        });
        return rec.subList(0, k);
    }


    public List<String> topKFrequent3(String[] words, int k) {

        //1.统计每个单词出现的次数
        Map<String,Integer> map = new HashMap<>();
        for (String word: words) {
            if(map.get(word) == null){
                map.put(word,1);
            }else{
                int val = map.get(word);
                map.put(word,val + 1);
            }
        }

        //2.通过上述代码，我们已经得到每个单词出现的次数，并存储到了Map中
        //也就是说，如果看到哪个单词出现的频率，接下来就是遍历map
        //创建小根堆
        PriorityQueue<Map.Entry<String,Integer>> minHeap = new PriorityQueue<>(
                //传入一个比较器
                new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                //当频率相同的时候，我们调整为大根堆
                if(o1.getValue().compareTo(o2.getValue()) == 0){
                    return o1.getKey().compareTo(o2.getKey());
                }

                //比较单词出现频率，创建小根堆
                return o1.getValue().compareTo(o2.getValue());
            }
        });


        //3.遍历map，将每个单词及其频率，存放的小根堆当中
        for (Map.Entry<String,Integer> entry : map.entrySet()) {
            //entry => hello --- 3
            if(minHeap.size() < k){
                minHeap.offer(entry);
            }else{
                //根堆顶元素进行比较
                Map.Entry<String,Integer> top = minHeap.peek();
                if(top.getValue().compareTo(entry.getValue()) == 0){
                    if(top.getKey().compareTo(entry.getKey()) > 0){
                        //堆顶是 def - 3,entry 是 abc - 3
                        //出堆
                        minHeap.poll();
                        minHeap.offer(entry);
                    }
                }else{
                    //频率不相同
                    //堆顶是 def - 3,entry 是 abc - 6,出栈
                    //堆顶是 def - 3,entry 是 abc - 2,不动
                    if(entry.getValue().compareTo(top.getValue()) > 0){
                        minHeap.poll();
                        minHeap.offer(entry);
                    }
                }
            }
        }
        //最后，需要逆置
        List<String> ret = new LinkedList<>();
        for (int i = 0; i < k; i++) {
            Map.Entry<String,Integer> tmp = minHeap.poll();
            ret.add(tmp.getKey());
        }
        //使得单词出现从高到低排序
        Collections.reverse(ret);
        return ret;
    }
}
